package com.jic.member.controller.manage;

import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.common.redis.RedisClientTemplate;
import com.jic.member.api.rest.MemberFavoriteManangeRestApi;
import com.jic.member.request.MemberFavoriteRestRequest;
import com.jic.member.response.MemberFavoriteRestResponse;
import com.jic.member.service.MemberFavoriteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author: MJ
 * @date: 2020-01-09
 * @remark: BBC接口 会员收藏列表
 */
@Slf4j
@RestController
@RequestMapping("/apiMyFavorite")
@Api(value = "APi-会员收藏",tags = "APi-会员收藏")
public class ApiMemberFavoriteController implements MemberFavoriteManangeRestApi {

    @Autowired
    RedisClientTemplate redisClientTemplate;

    @Autowired
    MemberFavoriteService memberFavoriteService;


    /**
     * BBC接口  店铺/商品 收藏、取消收藏
     * @param form
     * @return
     */
    @ApiOperation(value = "店铺、商品-收藏、取消收藏")
    @ResponseBody
    @PostMapping("/editMyFavorite")
    @Override
    public RestResult<String> editMyFavorite(@RequestBody MemberFavoriteRestRequest form) {
        RestResult restResult = new RestResult<>();
        try {
            restResult = memberFavoriteService.addCollects(form);
        } catch (Exception e) {
            log.error("error", e);
            restResult = RestResult.error("9999", "服务器出小差了....稍等片刻");
        }
        return restResult;
    }



    /**
     * BBC接口  收藏商品/店铺列表
     * @param form
     * @return
     */
    @ApiOperation(value = "收藏商品/店铺列表")
    @ResponseBody
    @PostMapping("/getFavoriteList")
    @Override
    public RestResult<PageResult<MemberFavoriteRestResponse>> getFavoriteList(@RequestBody MemberFavoriteRestRequest form) {
        RestResult restResult = new RestResult<>();
        try {
            restResult = memberFavoriteService.queryCollectionsPage(form);
        } catch (Exception e) {
            log.error("error", e);
            restResult=RestResult.error("9999",e.getLocalizedMessage());
        }
        return restResult;
    }

    @ApiOperation(value = "根据deptId查询店铺关注人数")
    @PostMapping("/queryFollowersByDeptId")
    @Override
    public RestResult queryFollowersByDeptId(@RequestBody MemberFavoriteRestRequest memberFavoriteRestRequest) {
        return memberFavoriteService.queryFollowersByDeptId(memberFavoriteRestRequest);
    }

    @Override
    public Boolean queryFollowersByEntityId(MemberFavoriteRestRequest memberFavoriteRestRequest) {
        return memberFavoriteService.queryFollowersByEntityId(memberFavoriteRestRequest);
    }

    @ApiOperation(value = "根据deptId查询店铺关注人数")
    @PostMapping("/countFollowersByDeptId")
    @Override
    public RestResult countFollowersByEntityId(MemberFavoriteRestRequest memberFavoriteRestRequest) {
        return memberFavoriteService.countFollowersByEntityId(memberFavoriteRestRequest);
    }

}
